import rxAjax from '@/assets/js/ajax.js';

//业务模型 api接口
export const FormBoDefApi = {};

FormBoDefApi.baseUrl= '/api-form/form/bo/formBoDef';
FormBoDefApi.exportUrl= FormBoDefApi.baseUrl + '/listExport';

//查询列表
FormBoDefApi.query=function (parameter) {
  var url= FormBoDefApi.baseUrl + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

/**
* 获取单记录
* @param pkId
* @returns {*}
*/
FormBoDefApi.get =function(pkId) {
  var url= FormBoDefApi.baseUrl + '/get?pkId=' + pkId;
  return rxAjax.get(url);
}

//保存数据
FormBoDefApi.save =function(parameter) {
  var url= FormBoDefApi.baseUrl + '/save';
  return rxAjax.postJson(url,parameter);
}

//删除数据
FormBoDefApi.del =function(parameter) {
  var url= FormBoDefApi.baseUrl + '/delBoDef';
  return rxAjax.postUrl(url,parameter);
}

FormBoDefApi.getBoJson=function(pkId){
  var url = FormBoDefApi.baseUrl + '/getBoJson?pkId='+pkId;
  return rxAjax.get(url);
}

FormBoDefApi.getBoDef = function (pkId) {
  var url = FormBoDefApi.baseUrl + '/getBoDef?pkId=' + pkId;
  return rxAjax.get(url);
}

/**
 * 根据bo别名获取数据结构。
 * @param boAlias
 * @returns {*}
 */
FormBoDefApi.getBoFields = function (boAlias) {
    var url = FormBoDefApi.baseUrl + '/getBoFields?boAlias=' + boAlias;
    return rxAjax.get(url);
}

FormBoDefApi.saveBoDef = function (parameter) {
  var url = FormBoDefApi.baseUrl + '/saveBoDef';
  return rxAjax.postJson(url, parameter);
}

FormBoDefApi.savePermission = function (parameter) {
  var url = FormBoDefApi.baseUrl + '/savePermission';
  return rxAjax.postJson(url, parameter);
}

FormBoDefApi.getJsonData = function (pkId) {
  var url = FormBoDefApi.baseUrl + '/getJsonData?pkId=' + pkId;
  return rxAjax.get(url);
}

FormBoDefApi.getRelForm = function (pkId) {
  var url = FormBoDefApi.baseUrl + '/getRelForm?pkId=' + pkId;
  return rxAjax.get(url);
}

FormBoDefApi.removeAttr = function (attrId) {
  var url = FormBoDefApi.baseUrl + '/removeAttr?attrId=' + attrId;
  return rxAjax.get(url);
}

FormBoDefApi.getBoDefConstruct = function (boDefId, isMain, entName,includeCommon) {
  var url = FormBoDefApi.baseUrl + '/getBoDefConstruct?boDefId=' + boDefId + '&isMain=' + isMain + '&entName=' + entName;
  if(includeCommon !=undefined){
      url += '&includeCommon=' + includeCommon;
  }
  return rxAjax.get(url);
}

/**
 * 获取bo定义.
 * @param {boDefId:"",includeCommon:false}
 * @returns {*}
 */
FormBoDefApi.getByDefIdCommonField = function ({boDefId="",needCommon=false}={}) {
    var url = FormBoDefApi.baseUrl + '/getByDefIdCommonField?pkId=' +  boDefId
    url+= '&needCommon=' + needCommon;
    return rxAjax.get(url);
}

FormBoDefApi.getBosByDefId = function (boDefId) {
  var url = FormBoDefApi.baseUrl + '/getBosByDefId?boDefId=' + boDefId;
  return rxAjax.get(url);
}

FormBoDefApi.getAttrByDefId = function (entId) {
    var url = FormBoDefApi.baseUrl + '/getAttrByEntId?entId=' + entId;
    return rxAjax.get(url);
}

FormBoDefApi.saveList=function(parameter){
    var url = FormBoDefApi.baseUrl + '/saveList';
    return rxAjax.postJson(url,parameter);
}

FormBoDefApi.batchChangesApp=function(parameter){
    var url = FormBoDefApi.baseUrl + '/batchChangesApp';
    return rxAjax.postJson(url,parameter);
}

FormBoDefApi.checkBeforeBatchChangesApp=function(parameter){
    var url = FormBoDefApi.baseUrl + '/checkBeforeBatchChangesApp';
    return rxAjax.postJson(url,parameter);
}

FormBoDefApi.update=function(parameter){
    var url = FormBoDefApi.baseUrl + '/update';
    return rxAjax.postJson(url,parameter);
}

FormBoDefApi.updExport=function(ids){
    var url= FormBoDefApi.baseUrl+'/updExport';
    return rxAjax.postForm(url, {ids:ids});
}

//变更分类
FormBoDefApi.changeCategory=function(ids,categoryId){
    var url= FormBoDefApi.baseUrl+'/changeCategory';
    return rxAjax.postForm(url, {ids:ids,categoryId:categoryId});
}

/**
 * 获取业务模型ID获取实体.
 * @param boDefId
 * @returns {*}
 */
FormBoDefApi.getBoIdFields = function (boDefId) {
    var url = FormBoDefApi.baseUrl + '/getBoIdFields?boDefId=' + boDefId;
    return rxAjax.get(url);
}

export default FormBoDefApi;

